//index.js
//获取应用实例
const wx = require('../../libs/wx.js');
const {getClerks} = require('../../apis');
const config = require('../../config');
const Page = require('../../libs/BasePage');

const app = getApp();
Page({
    data: {
        clerks: [],
        company: {}
    },

    onLoad () {
        getClerks().then((res) => {
            const clerks = res.data.data;

            this.setData({clerks});
        });

        app.getCompanyDetail().then((res) => {

            const {clerks, company, sales} = res;

            this.setData({company});
        })
    },

    onShareAppMessage() {
      return {
        title: config.name + ' - 店员',
        path: '/pages/clerks/clerks',
      }
    },

    previewImage(e){
        wx.previewImage({
            current: e.currentTarget.dataset.url,
            urls: e.currentTarget.dataset.urls
        })
    },

    goToDetail(e){
        const url = `../clerk/clerk?userId=${e.currentTarget.dataset.userid}&hot=${e.currentTarget.dataset.hot}&role=${e.currentTarget.dataset.role}`;
        wx.navigateTo({
            url
        })
    },


    onCallClick(){
        wx.makePhoneCall({
            phoneNumber: this.data.company.phoneNum || ''
        })
    },

    goToMap() {
        wx.openLocation({
            longitude: this.data.company.location[0],
            latitude: this.data.company.location[1],
            name: config.name,
            address: this.data.company.address
        });
    },

});
